package com.qhhc.controller;

import com.qhhc.entity.Role;
import com.qhhc.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
public class RoleController {
    @Autowired
    private IRoleService roleService;
    
    @RequestMapping("/getAllRoles")
    public List<Role> getAllRoles() {
        return roleService.getAllRoles();
    }
    
    @RequestMapping("/insertRole")
    public String insertRole(@RequestBody Role role) {
        roleService.insertRole(role);
        return "insertrole";
    }
    @RequestMapping("/deleteById")
    public String deleteById(@RequestBody Role role) {
        roleService.deleteRole(role);
        return "deleterole";
    }
    @RequestMapping("/updateRoleById")
    public String updateRoleById(@RequestBody Role role) {
        roleService.updateRole(role);
        System.out.println(role);
        return "updaterole";
    }
    @RequestMapping("/selectRoleById")
    public Role selectRoleById(@RequestParam long roleId) {
        Role roleById = roleService.getRoleById(roleId);
        return roleById;
    }
}
